#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int mod=1e9+7;
const int N=2e5+10;
ll a[N];
ll b[N];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",a+i);
		}
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",b+i);
		}
		sort(b+1,b+n+1,greater<int>());
		sort(a+1,a+n+1,greater<int>());
		int j=1;
		int f=1;
		ll ans=1;
		int j1=0;
		for(int i=1;i<=n;i++)
		{
			if(a[j]>b[i] || j1==n)
			{
				while(j<=n && a[j]>b[i])
				{
					j++;
				}
				j1=j-1;
				ans=ans*(j1-i+1)%mod;
			}
			else
			{
				if(j1<i)
				{
					f=0;
				    break;
				}
				ans=ans*(j1-i+1)%mod;
				
			}
		}
		if(f)
		{
			cout<<ans<<endl;
		}
		else
		{
			cout<<0<<endl;
		}
	}

	return 0;
}

